#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include "base_on_server.h"
using namespace BaseOnServer;

using namespace std;
int n =5;
vector<vector<int>> sub{{2,4},{1,3,5}};
vector<int> s{1,2,3,4,5};
vector<int> res;


bool sat(Set const& s){
    for(auto i:sub){
        if(includes(s.data.begin(),s.data.end(),i.begin(),i.end())){
            return true;
        }
    }
    return false;
}


struct Coro
{
    enum State { Start, Resume, Finish };
    State cur;
    int cnt;
    Set value;
    int depth;  

    Coro(int const& cnt_):
    cur(Start),cnt(cnt_),depth(0){

    }


    bool operator()(){
        if (cur == Finish) return false;    
        if (cur == Resume) goto CoroResume;
        cur = Resume;
        while (cnt<10)
        {
            cnt++;
            return true;
            CoroResume:;
        }
        cur = Finish;
        return false;
    }

    bool get_next(){
        if (cur == Finish) return false;    // 若已经结束
        if (cur == Resume) goto CoroResume; // 若之前已经运行过，则直接跳至返回处
        cur = Resume;
         
        bool flag1 = sat(value);
        bool flag2 = false;

        for(int i:s) {
            value = value + i;
            if(sat(value)){
                flag2 = true;
                depth++;
                get_next();
                depth--;
            }
            value = value - i;
        }
        if(flag1 && !flag2){
            bool tag = false;
            for(auto i:save){
                if(i.contain(value)){
                    tag = true;
                    break;
                }
            }
            if(!tag){
                save.insert(value);
                return true;
                CoroResume:;
            }
        }
        if(depth==0){
            cur = Finish;
            return false;
        }
    }
};

int main() {
    Coro coro();
    std::cout << "return:"<<coro.get_next() <<" val:"<< coro.cnt<<std::endl; // 1
    std::cout << "return:"<<coro.get_next() <<" val:"<< coro.cnt<<std::endl; // 1
}